cmake_minimum_required(VERSION 3.14)

project(FunctionalPlus VERSION 0.2.26)

# ---- Warning guard ----

# Protect dependents from this project's warnings if the guard isn't disabled
set(FunctionalPlus_warning_guard SYSTEM)
if (FunctionalPlus_INCLUDE_WITHOUT_SYSTEM)
    set(FunctionalPlus_warning_guard "")
endif ()

# ---- Declare library ----

add_library(fplus INTERFACE)
add_library(FunctionalPlus::fplus ALIAS fplus)
target_include_directories(
        fplus
        ${FunctionalPlus_warning_guard}
        INTERFACE
        "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
)

target_compile_features(fplus INTERFACE cxx_std_14)

find_package(Threads REQUIRED)
target_link_libraries(fplus INTERFACE Threads::Threads)

# ---- Create auto-generated fwd and curried functions, and amalgamated library ----

find_package(Python COMPONENTS Interpreter QUIET)
if (Python_FOUND)
    add_custom_target(
            auto_generate
            ALL
            COMMAND
            "${Python_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/generate/auto_generate.py"
            BYPRODUCTS
            "${PROJECT_SOURCE_DIR}/include/fplus/fwd_instances.autogenerated_defines"
            "${PROJECT_SOURCE_DIR}/include/fplus/curry_instances.autogenerated_defines"
            "${PROJECT_SOURCE_DIR}/include_all_in_one/include/fplus/fplus.hpp"
    )
    add_dependencies(fplus auto_generate)
else ()
    message(STATUS "Not adding the 'auto_generate' target (requires Python)")
endif ()

# ---- Install ----

include(cmake/install-rules.cmake)
